#include "random_generator.h"

Random_Generator :: Random_Generator () {
	A = 48271;
	M = 2147483647;
	Q = M/A;
	R = M%A;
	state = 1;
}

Random_Generator :: ~Random_Generator () {

}

/* Sets the variable responsible for generating the set of random numbers. */
void Random_Generator :: set_seed (long seed1, long seed2) {
	if (seed1 > seed2) {
		M = seed1;
		A = seed2;
	} else {
		A = seed1;
		M = seed2;
	}
}

/* Returns a random integer that can be in the range 0 to nonce - 1. */
long Random_Generator :: get_random (int nonce) {
	long t = A * (state % Q) - R * (state / Q);

	if (t > 0) {
		state = t;
	} else {
		state = t + M;
	}

	return (long) (((double) state / M) * nonce); 
}
